
using IGeekFan.AspNetCore.Knife4jUI;
using NLog;
using NLog.Web;
using RBAC.Api.Infaction;
using RBAC.Api.Read.Extensions;
using System.Reflection;

// 初始化NLog
var logger = NLog.LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger();
logger.Debug("初始化 RBAC.Api.Read");

try
{
    var builder = WebApplication.CreateBuilder(args);
    
    // 添加NLog
    builder.Logging.ClearProviders();
    builder.Host.UseNLog();
    
    builder = builder.Inject();


var app = builder.Build();



// Configure the HTTP request pipeline.

    app.UseSwagger();
   // app.UseSwaggerUI();

    app.UseKnife4UI();

//����
app.UseCors(x=>x.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());

app.UseAuthentication(); // 认证

app.UseAuthorization(); // 再授权

app.MapControllers();

app.Run();
}
catch (Exception ex)
{
    // 记录启动过程中的错误
    logger.Error(ex, "程序启动失败");
    throw;
}
finally
{
    // 确保在应用程序关闭时正确关闭NLog
    NLog.LogManager.Shutdown();
}
